// src/store/index.js
import { createStore } from 'vuex';

// 创建一个新的 store 实例
const store = createStore({
    state() {
        return {
            user: null, // 用户信息
        };
    },
    mutations: {
        setUser(state, user) {
            state.user = user;
        },
        clearUser(state) {
            state.user = null;
        }
    },
    actions: {
        loginUser({ commit }, user) {
            commit('setUser', user);
        },
        logoutUser({ commit }) {
            commit('clearUser');
        }
    },
    getters: {
        getUser(state) {
            return state.user;
        }
    }
});

export default store;